// index.js
// 获取应用实例
const app = getApp();
const imageCdn = "https://img.zcool.cn/community";
const swiperList = [
  `${imageCdn}/01511b5ebb446aa801207200585611.jpg`,
  `${imageCdn}/01f8c75ebb446ba801214814f229d9.jpg`,
  `${imageCdn}/01cd685ebb446aa801214814217a09.jpg`,
];

Page({
  data: {
    current: 0,
    autoplay: true,
    duration: 300,
    interval: 3000,
    swiperList,
    tabValue: 0,
    recommendList: [],
    todayList: [
      {
        imgSrc:
          "https://pic3.zhimg.com/v2-716e4903e843bd47f0506ad08e59e072_r.jpg",
        title: "【“葡萄爱马仕”】现摘阳光下的黑精灵",
        price: "75.00",
        rePrice: "98.00",
      },
      {
        imgSrc:
          "https://meishi.junyihuan.com/zb_users/upload/printer/20230403/642a3e7f5f88b.jpg",
        title: "【水果镶嵌，颗颗酸甜】携带维C的曲奇",
        price: "39.90",
        rePrice: "59.00",
      },
      {
        imgSrc:
          "https://img1.baidu.com/it/u=45805755,3772087394&fm=253&fmt=auto&app=138&f=JPEG?w=355&h=500",
        title: "【看得见的绿色】新鲜榨取蔬菜汁0防腐",
        price: "69.00",
        rePrice: "88.00",
      },
      {
        imgSrc:
          "https://gimg2.baidu.com/image_search/src=http%3A%2F%2Fimg.alicdn.com%2Ftfscom%2Fi3%2F2996338730%2FTB2w1umhznD8KJjSspbXXbbEXXa_%21%212996338730.jpg&refer=http%3A%2F%2Fimg.alicdn.com&app=2002&size=f9999,10000&q=a80&n=0&g=0n&fmt=auto?sec=1700201108&t=4996525a8efe6f17512fd356c2f14401",
        title: "【“悬空的自在”】Xxb吊床 舒适的感觉源于面向生活的设计",
        price: "139.90",
        rePrice: "159.00",
      },
      {
        imgSrc:
          "https://gimg2.baidu.com/image_search/src=http%3A%2F%2Fimg.alicdn.com%2Fbao%2Fuploaded%2Fi1%2F51172448%2FO1CN01b31N6P1TxEGLnmSv2_%21%2151172448.jpg&refer=http%3A%2F%2Fimg.alicdn.com&app=2002&size=f9999,10000&q=a80&n=0&g=0n&fmt=auto?sec=1700201141&t=6534d0c4e119f4f9a57d68f9a0479ddc",
        title: "【6件套】相约回忆中的老粗布",
        price: "159.90",
        rePrice: "199.00",
      },
    ],
    backTopTheme: "round",
    backTopText: "顶部",
  },
  onLoad() {
    this.getRecommendList();
  },
  onTabsChange(ev) {
    const tabValue = ev.detail.value;
    this.setData({ tabValue });
  },
  async getRecommendList() {
    const res = await wx.http.get("/api/public/v1/home/floordata");
    const recommendList = res.data.message;
    let newList = []
    const arr = recommendList.map(item => {
      for (let i = 0; i < item.product_list.length; i++) {
        let navigator_url = item.product_list[i].navigator_url
        let result = navigator_url.split('=')[1]
        item.product_list[i].navigator_url = result
      }
      return item
    })
    newList = [...arr]
    this.setData({ recommendList: newList });
  },
  onToTop(e) {
    // console.log("backToTop", e);
  },
});
